<?php
class Log_model extends CI_Model {

	function __construct()
    {
        parent::__construct();
    }

	public function add($data) {   
		$this->db->insert("log", $data);
		return $this->db->insert_id();
	}
	
	public function update($data, $id) {
		$this->db->where('id', $id);
		$this->db->update('log', $data); 
	}
	
	public function find_by_condition($condition, $offset = 0, $limit =20) {
		$sql = "select * from log  l 
				where 1=1 " . $condition .
				" order by l.created desc limit " . $offset . "," . $limit;
		$result = $this->db->query($sql)->result_array();
		return $result;
	}
	public function get_count_by_condition($condition) {
		$sql = "select count(*) as total from log  l 
				where 1=1 " . $condition ;
		$result = $this->db->query($sql)->row_array();
		return $result['total'];
	}
	
	public function delete($id) {
		$this->db->where('id', $id);
		$this->db->delete("log");
	}
	
	public function find_by_id($id) {
		$this->db->where('id', $id);
		return $this->db->get('log')->row_array();
	}
}